﻿using mozhi.smarterp.BasicData.Enums;
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;

namespace mozhi.smarterp.BasicData.Products
{
    public class ProductAuxiliaryUnit : AuditedAggregateRoot<Guid>, IMultiTenant
    {
        public  bool Activated { private set; get; }

        public  Guid? TenantId { get; private set; }

        public Guid ProductId { get; private set; }

        public Guid BasicUnitId { get; private set; }

        public Guid OtherUnitId { get; private set; }

        public AuxiliaryUnitRateType Type { get; private set; }

        /// <summary>
        /// 换算率
        /// </summary>
        public decimal ConversionRate {  get; private set; }

        private ProductAuxiliaryUnit() { }

        public ProductAuxiliaryUnit(Guid id , Guid productId , AuxiliaryUnitRateType type , Guid basicUnitId , Guid otherUnitId , decimal conversionRate , bool activated)
        {
            Id = id;
            ProductId = productId;
            BasicUnitId = basicUnitId;
            OtherUnitId = otherUnitId;
            ConversionRate = conversionRate;
            Type = type;
            Activated = activated;

            Validate();
        }

        public void Change(AuxiliaryUnitRateType type, Guid otherUnitId, decimal conversionRate, bool activated)
        {
            OtherUnitId = otherUnitId;
            ConversionRate = conversionRate;
            Type = type;
            Activated |= activated;
            Validate();
        }

        #region
        private void Validate()
        {
            Check.NotDefaultOrNull<Guid>(ProductId, nameof(ProductId));
            Check.NotDefaultOrNull<Guid>(BasicUnitId, nameof(BasicUnitId));
            Check.NotDefaultOrNull<Guid>(ProductId, nameof(ProductId));
            Check.NotDefaultOrNull<Guid>(OtherUnitId, nameof(OtherUnitId));
            Check.NotDefaultOrNull<decimal>(ConversionRate, nameof(ConversionRate));
            Check.NotDefaultOrNull<AuxiliaryUnitRateType>(Type, nameof(Type));
        }
        #endregion

    }
}
